package com.jill.jianghu.util.check.code;

import com.octo.captcha.service.captchastore.CaptchaStore;
import com.octo.captcha.service.captchastore.FastHashMapCaptchaStore;
import com.octo.captcha.service.image.DefaultManageableImageCaptchaService;


public class CaptchaService extends DefaultManageableImageCaptchaService {
	private static CaptchaService captchaService;
	
	private CaptchaService() {
		super();
	}

	private CaptchaService(int minSeconds, int maxStoreSize, int loadBefore) {
		super(minSeconds, maxStoreSize, loadBefore);
	}

	private CaptchaService(CaptchaStore captchaStore, CaptchaEngine captchaEngine, int minSeconds, int maxStoreSize, int loadBefore) {
		super(captchaStore, captchaEngine, minSeconds, maxStoreSize, loadBefore);
	}

	@Override
	public Boolean validateResponseForID(String ID, Object response) {
		Boolean isHuman;
		try {
			isHuman = super.validateResponseForID(ID, response);
		} catch (Exception e) {
			isHuman = false;
		}
		return isHuman;
	}
	
	public synchronized static CaptchaService getInstance(){
		if(null == captchaService){
			captchaService = new CaptchaService(new FastHashMapCaptchaStore(),new CaptchaEngine(), 300, 200000, 1);
			return captchaService;
		}else{
			return captchaService;
		}
	}
}
